﻿@model cloudscribe.Core.Web.ViewModels.RoleAdmin.RoleViewModel
@using cloudscribe.Core.Web
@using Microsoft.Extensions.Options
@using Microsoft.Extensions.Localization
@inject IStringLocalizer<CloudscribeCore> sr
@inject IOptions<SiteConfigOptions> setupOptionsAccessor
@{
    ViewData["BodyClass"] = "admin-section role-edit";
    var setupOptions = setupOptionsAccessor.Value;
}

<div class="row">
    <div class="col-md-10 col-md-push-2">
        <h2>@ViewData["Title"]</h2>
        <form asp-controller="RoleAdmin" asp-action="RoleEdit" data-submit-once="true">
            <input asp-for="Id" type="hidden" />
            <input asp-for="SiteId" type="hidden" />
            <input asp-for="NormalizedRoleName" type="hidden" />
            <div class="form-horizontal">
                <div asp-validation-summary="All" class="text-danger"></div>
                <div class="form-group">
                    <label asp-for="RoleName" class="col-md-2 control-label">@sr["Role Name"]</label>
                    <div class="col-md-10">
                        <input asp-for="RoleName" class="form-control" />
                        <span asp-validation-for="RoleName" class="text-danger"></span>
                        @Html.ValidationMessage("roleerror", new { @class = "text-danger" })
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-md-offset-2 col-md-10">
                        <button name="submit" type="submit" class="btn btn-default" data-disabled-text='@sr["Working..."]' data-enabled-text='@sr["Save"]'>@sr["Save"]</button>
                        @if (Model.IsDeletable(setupOptions.RolesThatCannotBeDeleted))
                        {
                            <button type="button" class="btn btn-danger" data-toggle="modal" data-target="#confirmDeleteModal">
                                @sr["Delete"]
                            </button>
                        }

                    </div>
                </div>
            </div>
        </form>

        <form class="form-inline" asp-controller="RoleAdmin" asp-action="RoleDelete">
            <input name="SiteId" value="@Model.SiteId" type="hidden" />
            <input id="roleId" name="roleId" type="hidden" value="@Model.Id" />
            <div class="modal fade" id="confirmDeleteModal" tabindex="-1" role="dialog" aria-labelledby="confirmDeleteHeading">
                <div class="modal-dialog modal-sm" role="document">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-label='@sr["Close"]'><span aria-hidden="true">&times;</span></button>
                            <h4 class="modal-title" id="confirmDeleteHeading">@sr["Confirm Delete"]</h4>
                        </div>
                        <div class="modal-body">
                            @string.Format(sr["Are you sure you want to delete {0}?"], Model.RoleName)
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">@sr["Cancel"]</button>
                            <input type="submit" value='@sr["Delete"]' class="btn btn-danger btn-ok" />
                        </div>
                    </div>
                </div>
            </div>

        </form>

    </div>
    <div class="col-md-2 col-md-pull-10 hidden-xs hidden-sm">
        @await Component.InvokeAsync("Navigation", new { viewName = "SideNavAlt1", filterName = NamedNavigationFilters.ParentTree, startingNodeKey = "SiteAdmin" })
    </div>
</div>
@section scripts {
    @{ await Html.RenderPartialAsync("_SideMenuScriptsPartial"); }
    @{ await Html.RenderPartialAsync("_UnobtrusiveValidationScriptsPartial"); }
    <script src="~/cr/js/jquery.validate.hooks.min.js"></script>
    <script src="~/cr/js/jqueryvaildation.submitonce-unobtrusive.min.js"></script>
}
